package com.kly.cashmall.module.home.home_tab.tab_container;

import android.content.Context;

import androidx.annotation.NonNull;

import com.kly.cashmall.module.home.home_tab.tab_view.FragmentPackage;
import com.kly.cashmall.module.home.home_tab.tab_view.HomeTabItem;
import com.kly.cashmall.module.home.home_tab.tab_view.MenuTabInfo;
import com.kly.cashmall.module.home.home_tab.tab_view.TabItem;

import java.util.ArrayList;
import java.util.List;

/**
 * @author
 * @date 2017/6/26
 */

public class HomePagesManager {
    private List<TabItem> tabItems = new ArrayList<>();

    /**
     * 设置fragmentPackages
     */
    public void setFragmentPackages(Context context, List<FragmentPackage<MenuTabInfo>> fragmentPackages) {
        if (fragmentPackages != null) {
            initTabItems(context, fragmentPackages);
        }
    }

    private void initTabItems(Context context, List<FragmentPackage<MenuTabInfo>> fragmentPackages) {
        tabItems.clear();
        for (FragmentPackage<MenuTabInfo> fragmentPackage : fragmentPackages) {
            tabItems.add(new HomeTabItem(context, fragmentPackage));
        }
    }

    /**
     * @return
     */
    public @NonNull
    List<TabItem> getTabItems() {
        return new ArrayList<>(tabItems);
    }

    public void clear() {
        tabItems.clear();
    }
}

